package com.shujia.mysql;

import com.shujia.util.JDBCUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Scanner;

public class Demo01Login {
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入用户:");
        String username = scanner.next();
        System.out.print("请输入密码:");
        String password = scanner.next();

        //业务逻辑
        Connection conn = JDBCUtil.getConn();
        String sql="select * from user where username=? and password=?";
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.setString(1,username);
        ps.setString(2,password);
        ResultSet rs = ps.executeQuery();
        User user = new User();
        while (rs.next()){
            user.setUsername(rs.getString("username"));
            user.setPassword(rs.getString("password"));
        }
        JDBCUtil.closeAll(conn,ps,rs);
        // update set password="123" where username=username1;
        //验证
        if(username.equals("")){
            System.out.println("用户名不能为空");
        }

        if(!password.equals(user.getPassword())){
            System.out.println("密码输入不正确");
        }
        System.out.println("登录成功");
        System.out.println("git");

    }
}
